<template>
  <div class="gq">
    <header>UIM_ADMIN</header>
    <el-form class="demo-ruleForm" :model="users" ref="loginForm" :rules="rules">
      <el-form-item label="用户名" prop="username">
        <el-input placeholder="请输入用户名" v-model="users.username"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input placeholder="请输入密码" type="password" v-model="users.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width:100%" @click="guoqin">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      users: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  mounted() {},
  methods: {
    guoqin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // 调用登录的接口
          this.$axios
            .post("/admin/login", this.users)
            .then(res => {
              console.log(res);
              this.$message("登录成功");
              let obj={
                token:res.data.token,
                username:res.data.username
                            }
             console.log(res)
              this.$store.commit("guoqin",obj);
              this.$router.push("/admin/gqhome");
            })
            .catch(error => {
              console.log(error.response.data);
              this.$message.error(error.response.data);
            });
        }
      });
    }
  },
  computed: {},
  watch: {}
};
</script>

<style lang="scss"scoped>
.gq {
  width: 30%;
  border: 1px solid #dddddd;
  padding: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  header {
    width: 100%;
    line-height: 60px;
    text-align: center;
    font-weight: bold;
    border-bottom: 1px solid #dddddd;
  }
  .el-form {
    margin-top: 10px;
  }
}
</style>